package com.patrol.controller;

import com.patrol.pojo.Example;
import com.patrol.service.ExampleService;
import com.patrol.utils.Msg;
import com.patrol.utils.TableMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
//@Controller
public class ExampleController {

    @Resource
    private ExampleService exampleService;

    @GetMapping("/getAll")
    public TableMap example() {
        List<Example> example = exampleService.example();
        TableMap tableMap = new TableMap();
        tableMap.setData(example);
        return tableMap;
    }

    /**
     * /getOneById/1
     * @param i
     * @return
     */
    @GetMapping("/getOneById/{id}")
    public Msg example1(@PathVariable("id") Integer i) {
        Example example = new Example();
        example.setId(1);
        example.setUsername("admin");
        if (null != example) {
            return Msg.success().add("key1", example);
        }
        return Msg.fail().add("key1", "查询为空");
    }
}
